home *** CD-ROM | disk | FTP | other *** search
- ' Mh.String.Input
- ' Copyright 1987 MicroHelp, Inc. - All Rights Reserved
-
- ' Requires MHDEF.INC for declaring constants
-
- ' CALL Mh.String.Input (Mh.Response$,Mh.Input.Mask$,Mh.Current.Pos%,_
- ' Mh.Cursor.Normal.Start%,Mh.Cursor.Normal.End%,_
- ' Mh.Cursor.Insert.Start%,Mh.Cursor.Insert.End%)
-
- '-------------------------------------------------------------------------
- ' Description - Edited string input according to the "masks" provided.
- ' Maximum length of string is determined by length of
- ' Mh.Input.Mask$. If a character in the mask is not
- ' a valid one, ANY character will be accepted for input.
-
- ' On entry - Set your colors and Locate to cursor position for input.
- ' Note that all numbers are INTEGERS. Use Mh.Current.Pos% to
- ' adjust actual starting point of edit.
-
- ' Mh.Response$=String that the user can edit
-
- ' Mh.Input.Mask$ - one character per input character allowed
- ' = Constant - for display only - no editing
- ' ? = Anything allowed
- ' # = 0-9 minus and space
- ' 9 = 0-9 only
- ' @ = 0-9 plus space
- ' A = Alpha (A-Z only) - convert to uppercase
- ' a = Alpha (A-Z only) - convert to lowercase
- ' B = Alpha plus space - convert to uppercase
- ' b = Alpha plus space - convert to lowercase
-
- ' Note that if an invalid mask character is encountered,
- ' it will be treated as '?', where ANYTHING is allowed
-
- ' Mh.Current.Pos%=Position within string at which to start editing
-
- ' Mh.Cursor.Normal.Start% = Start scan line
- ' Mh.Cursor.Normal.End% = Cursor end line
- ' Mh.Cursor.Insert.Start% = Start scan line
- ' Mh.Cursor.Insert.End% = End scan line
-
- ' On exit - Mh.Response$ contains edited input
- ' Mh.Terminator$(0) contains last keypress
- ' Mh.Current.Pos%=Last position at which a key was pressed
- '-------------------------------------------------------------------------
- SUB Mh.String.Input (Mh.Response$, Mh.Input.Mask$, Mh.Current.Pos%, Mh.Cursor.Normal.Start%, Mh.Cursor.Normal.End%, Mh.Cursor.Insert.Start%, Mh.Cursor.Insert.End%) STATIC
-
- DEFINT A-Z
-
- REM $INCLUDE: 'MhDef.Inc'
-
- IF Mh.Input.Mask$ = "" GOTO Final.exit ' too short
-
- Vertical = CSRLIN ' Find out where we are
- Horizontal = POS(0)
-
- Work.String$ = Mh.Response$ ' Pad work string if necessary
-
- IF LEN(Mh.Input.Mask$) > LEN(Work.String$) THEN ' fill out if too short
- Work.String$ = Work.String$ + STRING$(LEN(Mh.Input.Mask$) - LEN(Work.String$), Mh.Fill.Character%)
- END IF
-
- IF LEN(Mh.Input.Mask$) < LEN(Work.String$) THEN ' if response too long
- Mh.Input.Mask$ = Mh.Input.Mask$ + STRING$(LEN(Work.String$) - LEN(Mh.Input.Mask$), "?")
- END IF
-
- Max.Pos = LEN(Work.String$) ' Highest value that Mh.Current.Pos% can be
-
- If Mh.Current.Pos%<1 or Mh.Current.Pos%>Max.Pos Then
- Mh.Current.Pos%=1
-
- End if
-
- Show.String: ' Display the string
-
- LOCATE Vertical, Horizontal
- PRINT Work.String$;
-
- Position.Cursor:
-
- IF Insert.State THEN
- LOCATE Vertical, Horizontal + Mh.Current.Pos%-1, 1, Mh.Cursor.Insert.Start%, Mh.Cursor.Insert.End%
- ELSE
- LOCATE Vertical, Horizontal + Mh.Current.Pos%-1, 1, Mh.Cursor.Normal.Start%, Mh.Cursor.Normal.End%
- END IF
-
- Fetch.key:
-
- A$ = INKEY$
- IF A$ = "" GOTO Fetch.key
-
- LOCATE , , 0 ' turn off cursor
-
- Hit = 0 ' indicates found terminator character
- FOR N = 1 TO Mh.Terminators
- IF A$ = Mh.Terminator$(N) THEN
- Hit = N
- N = Mh.Terminators
- END IF
- NEXT
- IF Hit GOTO Finish.up.input ' if we found a terminator key
-
- IF LEN(A$) = 1 GOTO Ascii.Character
-
- A = ASC(MID$(A$, 2)) ' get scan code
- IF A = 75 GOTO Left.Arrow
- IF A = 77 GOTO Right.Arrow
- IF A = 71 GOTO Home
- IF A = 79 GOTO End.key
- IF A = 82 GOTO Toggle.Insert
- IF A = 83 GOTO Delete.key
- IF A = 116 GOTO Ctrl.Right
- IF A = 115 GOTO Ctrl.Left
-
- Bad.Key.Pressed:
-
- CALL Mh.Speaker ' Bad key pressed
- GOTO Position.Cursor
-
- Left.Arrow:
-
- Mh.Current.Pos% = Mh.Current.Pos% - 1
- GOTO Check.cursor
-
- Right.Arrow:
-
- Mh.Current.Pos% = Mh.Current.Pos% + 1
- GOTO Check.cursor
-
- Home:
-
- Mh.Current.Pos% = 1
- GOTO Position.Cursor
-
- End.key:
-
- Mh.Current.Pos% = Max.Pos
-
- Redo.End.Key: ' find last non space/fill character
-
- A = ASC(MID$(Work.String$, Mh.Current.Pos%))
- IF A <> 32 AND A <> Mh.Fill.Character GOTO Fudge.end.key
- IF Mh.Current.Pos% = 1 GOTO Position.Cursor
- Mh.Current.Pos% = Mh.Current.Pos% - 1
- GOTO Redo.End.Key
-
- Toggle.Insert:
-
- Insert.State = Insert.State XOR 1 ' toggle it
- GOTO Position.Cursor
-
- Delete.key:
-
- IF Mh.Current.Pos% = Max.Pos THEN
- MID$ (Work.String$, Mh.Current.Pos%, 1) = CHR$(Mh.Fill.Character)
- ELSE
- Work.String$ = LEFT$(Work.String$, Mh.Current.Pos%-1) + MID$(Work.String$, Mh.Current.Pos% + 1) + CHR$(Mh.Fill.Character)
- END IF
- GOTO Show.String
-
- Ctrl.Right:
-
- Ctrl.Factor = 1
- GOTO Redo.Ctrl.key
-
- Ctrl.Left:
-
- Ctrl.Factor = -1
-
- Redo.Ctrl.key:
-
- IF (Mh.Current.Pos% = 1 AND Ctrl.Factor = -1) OR (Mh.Current.Pos% = Max.Pos AND Ctrl.Factor = 1) GOTO Position.Cursor
-
- Mh.Current.Pos% = Mh.Current.Pos% + Ctrl.Factor
- A = ASC(MID$(Work.String$, Mh.Current.Pos%))
- A = INSTR(Word.separator$, CHR$(A))
- IF A = 0 GOTO Redo.Ctrl.key
- Mh.Current.Pos% = Mh.Current.Pos% + Ctrl.Factor ' one more so go past separator
- GOTO Position.Cursor
-
- Backspace:
-
- IF Mh.Current.Pos% = 1 THEN ' No backspace when at first character
- CALL Mh.Speaker
- GOTO Position.Cursor
- ELSE
- Mh.Current.Pos% = Mh.Current.Pos% - 1
- GOTO Delete.key ' same logic as backspace
- END IF
-
- Ascii.Character:
-
- IF ASC(A$) = 8 GOTO Backspace
-
- W$ = MID$(Mh.Input.Mask$, Mh.Current.Pos%, 1)' mask character
-
- ON INSTR("?#9@AaBb", W$) GOTO Character.ok, Num.minus.space, Num.only, Num.space, Alpha.caps.only, Alpha.lower.only, Alpha.caps.space, Alpha.lower.space
-
- GOTO Character.ok ' if mask character invalid, anything goes
-
- Num.minus.space:
-
- IF A$ = "-" GOTO Character.ok
-
- Num.space:
-
- IF A$ = " " GOTO Character.ok
-
- Num.only:
-
- IF INSTR("0123456789", A$) GOTO Character.ok
- GOTO Bad.Key.Pressed
-
- Alpha.caps.space:
-
- IF A$ = " " GOTO Character.ok
-
- Alpha.caps.only:
-
- A$ = CHR$(ASC(A$) AND 223) ' Turn off lower case bit
- IF A$ >= "A" AND A$ <= "Z" GOTO Character.ok
- GOTO Bad.Key.Pressed
-
- Alpha.lower.space:
-
- IF A$ = " " GOTO Character.ok
-
- Alpha.lower.only:
-
- A$ = CHR$(ASC(A$) OR 32) ' Turn on lower case bit
- IF A$ >= "a" AND A$ <= "z" GOTO Character.ok
- GOTO Bad.Key.Pressed
-
- Character.ok:
-
- IF Mh.Current.Pos% = Max.Pos OR Insert.State = False THEN
- MID$ (Work.String$, Mh.Current.Pos%) = A$
- ELSE
- Work.String$ = LEFT$(Work.String$, Mh.Current.Pos%-1) + A$ + MID$(Work.String$, Mh.Current.Pos%)
- Work.String$ = LEFT$(Work.String$, LEN(Work.String$) - 1)
- ' we have to strip one character because we added one
- END IF
-
- IF Mh.Current.Pos% = Max.Pos AND Mh.Auto.Terminate = True GOTO Finish.up.input
-
- Fudge.end.key:
-
- IF Mh.Current.Pos% <> Max.Pos THEN Mh.Current.Pos% = Mh.Current.Pos% + 1
- GOTO Show.String
-
- Check.cursor:
-
- IF Mh.Current.Pos% > Max.Pos THEN
- Mh.Current.Pos% = Max.Pos
- CALL Mh.Speaker
- END IF
-
- IF Mh.Current.Pos% < 1 THEN
- Mh.Current.Pos% = 1
- CALL Mh.Speaker
- END IF
- GOTO Show.String
-
- Finish.up.input: ' set variables and return
-
- LOCATE Vertical, Horizontal
- PRINT Work.String$;
-
- Hit = LEN(Work.String$) ' new length of string
-
- FOR N = Hit TO 1 STEP -1 ' strip from right
- IF ASC(MID$(Work.String$, N)) <> Mh.Fill.Character% AND ASC(MID$(Work.String$, N)) <> 32 THEN
- Hit = N
- N = 1
- END IF
- NEXT
-
- Work.String$ = LEFT$(Work.String$, Hit)
-
- FOR N = 1 TO LEN(Work.String$) ' replace fill character with spaces
- IF ASC(MID$(Work.String$, N)) = Mh.Fill.Character% THEN
- MID$ (Work.String$, N, 1) = CHR$(32)
- END IF
- NEXT
-
- Final.exit:
-
- Mh.Response$ = Work.String$
- Mh.Terminator$(0) = A$ ' set last key entered
-
- END SUB
-